<?php
class ModelCatalogCategory extends Model {
	
	public function getCategories() {
		$page=array(
		array('name'=>'首页','page_id'=>'1','top'=>'1','column'=>'1','page_path'=>'home'),	
		array('name'=>'我是雇主','page_id'=>'2','top'=>'1','column'=>'1','page_path'=>'boss'),
		array('name'=>'我是员工','page_id'=>'3','top'=>'1','column'=>'1','page_path'=>'staff'),
		array('name'=>'我的资料','page_id'=>'4','top'=>'1','column'=>'1','page_path'=>'myinformation'),
		array('name'=>'我的微博','page_id'=>'5','top'=>'1','column'=>'1','page_path'=>'mytweet')
		); 
		
		return $page;
	}
	
	public function getChildren($id) {
		
		$page=array(
		array('name'=>'首页','page_id'=>'1','top'=>'1','column'=>'1'),
		array('name'=>'我是雇主','page_id'=>'2','top'=>'1','column'=>'1'),
		array('name'=>'我是员工','page_id'=>'3','top'=>'1','column'=>'1'),
		array('name'=>'我的微博','page_id'=>'4','top'=>'1','column'=>'1')
		);
		
		$children=array();
		
		return $children;
	}

	public function getCategoriesByParentId($category_id) {
		$category_data = array();
		
		$category_data[] = $category_id;
		
		$category_query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "category WHERE parent_id = '" . (int)$category_id . "'");
		
		foreach ($category_query->rows as $category) {
			$children = $this->getCategoriesByParentId($category['category_id']);
			
			if ($children) {
				$category_data = array_merge($children, $category_data);
			}			
		}
		
		return $category_data;
	}
		
	public function getCategoryLayoutId($category_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_to_layout WHERE category_id = '" . (int)$category_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
		if ($query->num_rows) {
			return $query->row['layout_id'];
		} else {
			return $this->config->get('config_layout_category');
		}
	}
					
	public function getTotalCategoriesByCategoryId($parent_id = 0) {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND c.status = '1'");
		
		return $query->row['total'];
	}
}
?>